//清除缓存
localStorage.clear();
 
$(".btn-regist").on('click', function() {
	//防止重复点击
	$(this).attr("disabled", true);
	var mail = $('.mail-input').val();
	var name = $('.name-input').val();
	var password = $('.pwd-input').val();
	var phone = $('.phone-input').val();
	var username = $('.user-input').val();
	
	if(!mail || !name || !password || !phone || !username) {
		layer.msg("所有信息均不能为空！");
		$(this).removeAttr("disabled");
		return false;
	}
	
	var _that=$(this);
	var d = {};
	d.mail = mail;
	d.name = name;
	d.password = password;
	d.phone = phone;
	d.username = username;
	
	$.ajax({
		url: url + "/sys/register",
		type: 'POST',
		//		参数需转为字符串
		data: JSON.stringify(d),
		//		json跨域
		dataType: 'json',
		//		contentType类型为json
		contentType: "application/json",

		//		请求头加上X-Token 
		 beforeSend: function(XMLHttpRequest) {
			//		token 为页面所获取
			   
//			XMLHttpRequest.setRequestHeader("X-Token", token); 
		},
		useDefaultXhrHeader: false,
		success: function(result) {
			console.log(result);
			if(result.code == '0') {
				layer.msg(result.msg,{time:1*1000},function() {
					window.location.href = 'login.html';
				});
				
			} else {
				layer.msg(result.msg);
				$(_that).removeAttr("disabled");
			}
		},
		err: function(err) {
			layer.msg("请求失败");
			$(_that).removeAttr("disabled");
		},
		complete: function() {
			$(_that).removeAttr("disabled");
		}
	});
});

